
package com.sausageking.server;

import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;

import com.sausageking.shared.BuyerException;
import com.sausageking.shared.BuyerException.Code;
import com.sausageking.shared.Merchant;

public class MerchantTokenManagerImpl implements MerchantTokenManager {

  private AuthManager authManager = new AuthManagerImpl();

  @Override
  public void validate(Merchant merchant, String merchantToken)
      throws BuyerException {
    DateTime date = new DateTime(DateTimeZone.forID(merchant.getTimeZoneId()));
    if (!authManager.validatePurchaseConfirmationCode(merchant, date, merchantToken)) {
      throw new BuyerException(Code.INVALID_ORDER_CONFIMRATION_CODE);
    }
  }
}
